<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; utf-8">
    <title>我的中心</title>
    <%@ include file="../../static/top.jsp" %>

    <style>
        
        th{
        	min-width: 80px;
        }
    </style>
</head>
<body class="sticky-header">

<section> <!-- left side start-->
    <%@ include
            file="../../static/menu.jsp" %> <!-- left side end-->

    <!-- main content start-->
    <div class="main-content">

        <!-- header section start-->


        <%@ include file="../../static/header.jsp" %>

        <div class="wrapper">
			<div class="page-heading">
				<ul class="breadcrumb">
					<li><a href="#">我的采集</a></li>
					<li><a href="/action/my/m/toTemplateConfig?mid=a1&aid=ch12">模板配置</a></li>
					<li class="active">关联链接</li>
				</ul>
			</div>
            <div class="row">
                <div class="col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">链接列表</div>
                        <div class="panel-body">

                            

                            <div class="col-md-12">

                                <div class="panel ">
                                    <div class="panel-heading">${title}</div>
                                    <div class="panel-body" >
                                    <div class="col-md-12">

			                                <form class="form-horizontal" role="form">
			                                    <div class="form-group col-sm-10">
			                                        <button id="addUrlBtn" type="button"
			                                                class="  btn btn-info">关联链接
			                                        </button>
													<button id="startBtn" type="button"
			                                                class="  btn btn-danger">开始采集
			                                        </button>
			                                    </div>
			                                    
			                                    
			                                    
			                                   
		                                    <div class="form-group">
		
		                                        <label for="username" class="col-sm-2 control-label">下载状态</label>
		
		                                        <div class="col-sm-3 ">
		                                            <select id="status" class="form-control"> 
		                                            	<option value="">请选择...</option>
		                                            	<option value="0">待采集</option>
		                                            	<option value="1">采集中</option>
		                                            	<option value="2">采集完成</option>
		                                            	<option value="3">采集失败</option>
		                                            	<option value="4">解析中</option>
		                                            	<option value="5">解析完成</option>
		                                            	<option value="6">解析失败</option>
		                                            </select>
		                                        </div>
		                                        <div class="col-sm-2 ">
		                                            <button id="searchBtn" type="button" class="btn btn-success">查询</button>
		                                        </div>
		                                        
		                                        
		                                    </div>

                              
			
			                                </form>
			
			                            </div>
                                        <table class="table table-bordered table-striped table-condensed">
                                            <thead>
                                            <tr id="thead">
 											
                                                <td >顺序</td>
                                              
                                                <td >网址</td>
                                               	<td >状态</td>
                                              	<td >操作</td>
                                            </tr>
                                            </thead>
                                            <tbody id="tbody">


                                            </tbody>
                                        </table>

                                    </div>
                                </div>
                                <div class="paging">
									<ul class="pagination" id="Pagination">

									</ul>
								</div>


                            </div>
                        </div>
                    </div>
                </div>

            </div>

        </div>
        <!--body wrapper end-->


        <!--footer section start-->
        <%@ include file="../../static/footer.jsp" %>

        <!--footer section end-->

        
        
    </div>

    </section>
    
    <div tabindex="-1" role="dialog" id="createUrl"
             class="modal fade bs-example-modal-lg" style="display: none;">
            <div role="document" class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" data-dismiss="modal" aria-label="Close"
                                class="close">
                            <span aria-hidden="true">×</span>
                        </button>
                        <h4 class="modal-title">关联的url</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal">
                            <div class="form-group">
                                <label class="control-label col-sm-10">${title}</label>
                              
                            </div>
                            <div class="form-group">
                               
                                <label class="control-label col-sm-2">输入网址</label>
                            </div>
                            <div class="form-group">
                               
                                <div class="col-sm-12" id="newTableDiv">
                                    <textarea rows="12" class="form-control" id="urls"></textarea>
                                </div>
                            </div>
                            
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-info" id="saveBtn">保存 </button>
                        <button type="button" class="btn btn-success" id="closeBtn" >关闭</button>
                    </div>
                </div>
            </div>
        </div>

<script type="text/javascript">
var JOB_STATUS = {
		
		0 : {
			name : "待采集",
			value : '0'
		},
		1 : {
			name : "采集中",
			value : '1'
		},
		2 : {
			name : "采集完成",
			value : '2'
		},
		3 : {
			name : "采集失败",
			value : '3'
		},
		4 : {
			name : "解析中",
			value : '4'
		},
		5 : {
			name : "解析完成",
			value : '5'
		},
		6 : {
			name : "解析失败",
			value : '6'
		},
		
		"length" : 7
	};
var pageSize = 20, pageinit = true;	
var request_id = '${request_id}';
$(document).ready(function () {
	queryList(1, true);
	
	 $("#addUrlBtn").click(function () {
		 
	     $("#urls").val("");
	     $("#createUrl").modal("show");
	     
	 });
	 
 	$("#searchBtn").click(function () {
		 
 		queryList(1, true);
	     
	 });
	 
	 
 	$("#startBtn").click(function () {
 		var status = $("#status").val();
 		layer.confirm('确定开始下载列表的数据？', {
 			  btn: ['确定','取消'] //按钮
 			}, function(){
 				//$.blockUI({ message: '<h1>请稍等...</h1> ', css: { width: '200px', height: '100px' } });
 				$.post("/action/my/url/startUrl",{"request_id":request_id,"status":status},function(data){
 					//$.unblockUI();
 					if(data.code==200){
 						layer.msg("操作成功");
 					
 					}else{
 						layer.msg(data.msg)
 					}
 				})
 				
 			});
	 });
	 
	 
	 $("#saveBtn").click(function () {
		var urls = $("#urls").val();
		var status = $("#status").val();
		if(urls==''||urls==undefined){
			layer.msg("请输入网址");
			return;
		}
		
		$.post("/action/my/url/saveMyUrl",{"urls" : urls,"request_id":request_id,"status":status},function(data){
			if(data.code==200){
				layer.msg("操作成功");
				$("#createUrl").modal("hide");
				queryList(1, true);
			}else{
				layer.msg(data.msg)
			}
		})
       
     })
	 $("#closeBtn").click(function () {
		
		$("#urls").val("");
        $("#createUrl").modal("hide");
     })
});
    
function queryList(page, pageinit) {
	$("#tbody").empty();
	var status = $("#status").val();
	 $.get("/action/my/url/getMyUrl",{"request_id":request_id,"pageNum" : page,"pageSize" : pageSize,"status":status},function(data){
		 var contain, content;
			var _totalPage = data.maxPage;
			if (data.data.length) {
				for (var i = 0; i < data.data.length; i++) {
					contain = data.data[i];
					
					content += "<tr><td>"+ contain.orderby + "</td>" ;
					content += "<td>"+ contain.url + "</td>" ;
					content += "<td>"+ JOB_STATUS[contain.status].name + "</td>" ;
					content += "<td><a href='javascript:void(0)' onclick='repStartUrl("+contain.id+")'>重试</a></td>";
					content += "</tr>" ;

				}
				$("#tbody").append(content);
			}
			if (pageinit) {
				$('#Pagination').empty();
				$.jqPaginator('#Pagination',{
					totalPages : _totalPage,
					visiblePages : 10,
					currentPage : 1,
					prev : '<li class="prev"><a href="javascript:scroll(0,0)">上页</a></li>',
					next : '<li class="next"><a href="javascript:scroll(0,0)">下页</a></li>',
					first : '<li class="first"><a href="javascript:scroll(0,0)">首页</a></li>',
					last : '<li class="last"><a href="javascript:scroll(0,0)">尾页</a></li>',
					page : '<li class="page"><a href="javascript:scroll(0,0)">{{page}}</a></li>',
					onPageChange : function(num, type) {
						if ((this.currentPage != 1)|| (1 != num)) {
							queryList(num,false);
						}
					}
				});
			}
	  })
	
}
 

function repStartUrl(id){
	layer.confirm('确定下载此数据？', {
		  btn: ['确定','取消'] //按钮
		}, function(){
		 
			$.post("/action/my/m/repStartUrl",{"id":id},function(data){
				if(data.code==200){
					layer.msg("操作成功");
				
				}else{
					layer.msg(data.msg)
				}
			})
			
		});
}

</script>

</body>
</html>
